package com.momochen.alarmclockdemo.adapter;

import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.momochen.alarmclockdemo.AlarmConstant;
import com.momochen.alarmclockdemo.R;
import com.momochen.alarmclockdemo.bean.AlarmBean;

import java.util.Calendar;

/**
 * Created by momochen on 2017-07-09.
 */

public class TimeAdapter extends BaseListAdapter<AlarmBean, TimeAdapter.ItemViewHoler> {

    @Override
    public ItemViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_time, parent, false);
        return new ItemViewHoler(view);
    }

    @Override
    public void onBindViewHolder(ItemViewHoler holder, int position) {

        AlarmBean alarm = getItem(position);
        if (alarm == null) {
            return;
        }

        holder.tvNote.setText(alarm.getNote());

        final Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, alarm.getHour());
        calendar.set(Calendar.MINUTE, alarm.getMinutes());
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        holder.tvTime.setText(DateFormat.format(AlarmConstant.DM24, calendar));

    }

    class ItemViewHoler extends BaseListViewHolder {
        public TextView tvTime;
        public TextView tvAm;
        public TextView tvNote;

        public ItemViewHoler(View itemView) {
            super(itemView, onClickRecyclerItemListener);
            tvTime = itemView.findViewById(R.id.tv_time);
            tvAm = itemView.findViewById(R.id.tv_am_pm);
            tvNote = itemView.findViewById(R.id.tv_note);
        }
    }
}
